#!/bin/bash
# 这个脚本用于编译各种平台一键构建脚本
# 支持Linux-x86_64、android aarch64 、android aarch32


function  build_Linux_x86_64(){
    echo "build_Linux_x86_64"
    rm -rf build_linux_x86_64
    mkdir build_linux_x86_64
    cd build_linux_x86_64

    cmake  -DCMAKE_BUILD_TYPE=Release  ..

    make -j4
    cd ..
}


 function  build_Linux_aarch64(){
     echo "build_Linux_aarch64"

     rm -rf build_linux_aarch64
     mkdir build_linux_aarch64
     cd build_linux_aarch64

     # CURRENT_DIR=$(cd $(dirname $0); pwd)  当前路径
     PARENT_DIR=$(cd $(dirname $0);cd ..; pwd) #上层路径

     echo $PARENT_DIR

     cmake  -DCMAKE_TOOLCHAIN_FILE=${PARENT_DIR}/toolchains/linux-aarch64-arm.toolchain.cmake \
     -DCMAKE_BUILD_TYPE=Release   ..

     make -j4
     cd ..
 }


##平台数组
Plant_array=(
linux 
)


#芯片架构数组
Architecture_array=(
x86_64
aarch64
)
 
# $1 如果存在，输出 $1 exists，$1 如果不存在，输出 $1 not exists
if [[ "$1" != "" && "$2" != "" ]];then
    if [[ "${Plant_array[@]}"  =~ "${1}" && "${Architecture_array[@]}"  =~ "${2}" ]]; then
        echo "$1  $2 exists"
        if [[ "${1}" == "linux" && "${2}" == "x86_64"  ]]; then
            build_Linux_x86_64
        elif [[ "${1}" == "linux" && "${2}" == "aarch64"  ]]; then
            build_Linux_aarch64
        else
            echo "不支持的平台架构选项！"
        fi

    elif [[ ! "${Plant_array[@]}"  =~ "${1}"  ||  ! "${Architecture_array[@]}"  =~ "${2}" ]]; then
        echo "$1 $2 not exists"
    fi
else
    echo "请传入 平台类型 芯片架构/项目名称 两个参数"
    echo "编译例子如下："
    echo "build.sh 平台类型 芯片架构/项目名称"
    echo "build.sh linux x86_64"
    # echo "build.sh linux th518"
    echo "build.sh linux aarch64"
    # echo "build.sh android aarch32"
fi

